package com.ttc.group2.videochat.utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.quickblox.users.model.QBUser;
import com.ttc.group2.videochat.model.User;

public class UserUtils {

	public static User createUser(QBUser qbUser) {
		User user = new User();
		user.setUserId(qbUser.getId());
		user.setFullName(qbUser.getFullName());
		user.setEmail(qbUser.getEmail());
		user.setLastRequestAt(qbUser.getLastRequestAt());

		return user;
	}

	public static List<User> createUsersList(Collection<QBUser> qbUsers) {
		List<User> users = new ArrayList<User>();
		for (QBUser user : qbUsers) {
			users.add(createUser(user));
		}
		return users;
	}

	public static Map<Integer, User> createUserMap(List<QBUser> userList) {
		Map<Integer, User> userHashMap = new HashMap<Integer, User>();
		for (QBUser user : userList) {
			userHashMap.put(user.getId(), createUser(user));
		}
		return userHashMap;
	}
	
	public static QBUser userToQBUser(User user) {
		if (user == null) {
			return null;
		}
		QBUser qbUser = new QBUser();
		qbUser.setId(user.getUserId());
		qbUser.setFullName(qbUser.getFullName());
		return qbUser;
	}

}
